<title>del smiles</title>
<div class="layui-card layadmin-header">
<div class="layui-breadcrumb" lay-filter="breadcrumb">
    <a lay-href="">主页</a>
    <a><cite>应用</cite></a>
    <a><cite>delSmileList</cite></a>
</div>
</div>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <table id="delSmile" lay-filter="delSmile"></table>
            <script type="text/html" id="table-delSmile-list">
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="res"><i class="layui-icon layui-icon-refresh-1"></i>还原</a>
            </script>
        </div>
        <div id="delSmilePage" style="text-align: center"></div>
    </div>
</div>
<script>
    layui.use(['admin', 'table','server','laypage'], function(){
        var $ = layui.$
        ,admin = layui.admin
        ,table = layui.table
        ,form = layui.form
        ,server = layui.server
        ,setter = layui.setter
        ,laypage = layui.laypage
        var options = {};
        var page_size = setter.page_size;
        var main = {page_size:page_size,page:1};
        options.url = 'getdelSmile';
        options.data = main;
        options.callback = function(data){
            var result = [];
            if(data.total > 0){
                result = data.data;
            }
            table.render({
                elem: '#delSmile',
                limit:page_size,
                cols: [[
                    {field:'id',type: 'checkbox',hide:true},
                    {field: 'content',title: '内容'},
                    {field: 'time', title: '时间'},
                    {fixed: 'right', align:'center', toolbar: '#table-delSmile-list',title:'操作',width:'20%'}
                ]],
                data:result
            });

            smilePage(data,main);
        }
        server.req(options);

        table.on('tool(delSmile)',function(obj){
            var linedata = obj.data; //获得当前行数据
            var layEvent = obj.event;
            if(layEvent == 'res'){
                layer.confirm('确定还原这个？',{
                    btn: ['是的','不得']
                },function(){
                    var del_options = {};
                    del_options.url = 'resdelSmile';
                    del_options.data = {
                        id:linedata.id
                    },
                    del_options.callback = function(data){
                        obj.del();
                        layer.closeAll();
                    }
                    server.req(del_options);
                });
            }
        });

        function smilePage(data,main) {
            laypage.render({
                elem: 'delSmilePage',
                count: data.total,
                limit:page_size,
                jump: function(obj, first){
                    // //首次不执行
                    if(!first){
                        main.page = obj.curr;
                        reloadTable(main);
                    }
                }
            });
        }

        function reloadTable(main){
            var options = {};
            options.url = 'getdelSmile';
            options.data = main;
            options.callback = function(data){
                var result = [];
                if(data.total >0){
                    result = data.data;
                }
                table.reload('delSmile', {
                    data:result
                });
            }
            server.req(options);
        }
    });
</script>